from prettytable import PrettyTable

# pip install prettytable
# 独自完成的
# 传入的 name、age、country 相当于表头
tb = PrettyTable(["号行", "座位1", "座位2", "座位3", "座位4", "座位5"])

lst = []
for i in range(0, 6):
    sub_list = ['有票' for z in range(0, 5)]
    sub_list.insert(0, f"第{i + 1}行")
    lst.append(sub_list)
tb.add_rows(lst)
print(tb)

total_row = len(lst)
total_cols = len(lst[0])
while True:
    str1 = input("请输入行和列使用逗号分割 比如 1,1 选择第一行和第一列:")
    if str1 == "quit" or str1 == "exit":
        break
    in_list = str1.split(",")
    row = int(in_list[0])
    row_index = row - 1
    col = int(in_list[1])
    col_index = col
    print(f"row={row_index},col={col}")
    if row_index < 0 or col_index < 1 or row_index > total_row or col_index >= total_cols:
        print("超过了访问范围")
        continue
    if lst[row_index][col_index] == "有票":
        lst[row_index][col_index] = '已售'
        tb.clear_rows()
        tb.add_rows(lst)
        print(tb)
    else:
        print(f"行：{row},列:{col} 已经售完了。")
